<template>
  <div id="Login">
    <p>
      账号：<input type="text" v-model="user.username">
    </p>
    <p>
      密码：<input type="password" v-model="user.password">
    </p>
    <input type="button" @click="login" value="登录">
  </div>
</template>

<script>
  import axios from 'axios'
  import {product} from "../../api";
  export default {
    name: "Login",
    data(){
      return {
          user:{
            username:'a120',
            password:'jxx123.0'
          }
      }
    },
    methods:{
      login(){
         console.log(this.$store.state.user.userNickName)// 取store的值
          this.$API.user.login(this.user).then(res=>{
            console.log(res)
            if(res.data && res.data.token){
                this.$store.dispatch("login",res.data);// 修改store值
                this.$message({
                  message: '登录成功，正在跳转',
                  type: 'success',
                  duration:1000
                });
                let self = this;
                setTimeout(function (){
                  self.$router.push({path:"/"})
                },1000)
            }
          })
      }
    }
  }
</script>
<!-- scoped 局部样式 -->
<style scoped>
  body{
    background: aqua;
  }
</style>
